import javax.swing.event.DocumentListener
import javax.swing.event.DocumentEvent
import net.miginfocom.swing.MigLayout


application(title:'FireTest',
  size:[800,600],
  locationByPlatform:true,
  iconImage: imageIcon('/griffon-icon-48x48.png').image,
  iconImages: [imageIcon('/griffon-icon-48x48.png').image,
               imageIcon('/griffon-icon-32x32.png').image,
               imageIcon('/griffon-icon-16x16.png').image]
) {
    lookAndFeel('system')
    panel(layout: new MigLayout('fill')) {

        panel(layout: new MigLayout('fill'), constraints: 'grow 100 1, wrap, height 10%' ) {
            
            comboBox(id: 'methodType',
                items: ["GET", "POST", "PUT"],
                selectedIndex: 0,                
                constraints: "growx,width 30px"
            )
            
            label( id:'urllbl',
                text: "URL:",
                constraints: "shrinkx,height 25px,width 20px"
            )
            textField( id:'urlTxt',
                constraints: "shrink,height 25px,width 75%"
            )
            
            button ( id: 'sendBtn',
                label: "Fire !",
				actionPerformed: {controller.doSubmit()},
                constraints: "width 10% ,shrinkx,wrap"
            )
			
        }

        panel(layout: new MigLayout('fill'), border: titledBorder('Data'), constraints: 'grow 100 1, wrap, height 70%') {
            
            
             panel(layout: new MigLayout('fill'), constraints: 'grow 50 ' ) {
             	 label('Request:', constraints: 'left')
		 button ( id: 'clearReq',
			  label: "Clear",
		          actionPerformed: {this.reqTxt.text=""},
		          constraints: "right,width 10px ,shrinkx,shrinky"
            		)
             }
            
             panel(layout: new MigLayout('fill'), constraints: 'grow 50 , wrap' ) {
	                label('Response:', constraints: 'left')
	                button ( id: 'clearRes',
				 label: "Clear",
				 actionPerformed: {this.resTxt.text=""},
				 constraints: "right,width 10px ,shrinkx,shrinky"
            		)
	                
             }
            
            
            
            scrollPane(constraints: 'grow,width 50%, height 70%') {
                textArea(id: "reqTxt",
                    editable: true,
                    lineWrap: true,
                    wrapStyleWord: true)
            }

            scrollPane(constraints: 'grow,width 50%, height 70%, wrap') {
				 textArea(id: "resTxt",
                    editable: true,
                    lineWrap: true,
                    wrapStyleWord: true)
            }
        }

        panel(layout: new MigLayout('fill'), border: titledBorder('Log'), constraints: 'grow 100 1, wrap, height 30%') {
             button ( id: 'clearLog',
	    			  label: "Clear",
	    		          actionPerformed: {this.logTxt.text=""},
	    		          constraints: "right,width 10px ,shrinkx,shrinky,wrap"
            		)
            scrollPane(constraints: 'growx,width 100%,height 80%,span') {
				 textArea(id: "logTxt",
                    editable: false,
                    lineWrap: true,
                    wrapStyleWord: true)
            }
        }      

    }
    
    
    reqTxt.getDocument().addDocumentListener(  { evt ->
    
    						  insertUpdate : { this.resTxt.text=""}
    						  removeUpdate : { this.resTxt.text=""}
    						  changedUpdate : { this.resTxt.text=""}
    						
    						
    					       } as DocumentListener)    
  
}
